package com.evernote.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.evernote.entity.Content;
import com.evernote.service.ContentService;

/**
 * Servlet implementation class DoSelectNotebook
 */
@WebServlet("/DoSelectNotebook")
public class DoSelectNotebook extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DoSelectNotebook() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("utf-8");
		
		int Nid = Integer.parseInt(request.getParameter("Nid"));
		int Uid = Integer.parseInt(request.getParameter("Uid"));
		
		Content c = new Content();
		ContentService cs = new ContentService();
		List<Content> clist = new ArrayList<>();
		
		c.setNid(Nid);
		clist = cs.findAllContentByNid(c);
		
		request.setAttribute("clist", clist);
		request.setAttribute("Uid", Uid);
		request.setAttribute("Nid", Nid);
		request.setAttribute("selectedNid", Nid);
		request.getRequestDispatcher("ToIndex").forward(request, response);
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
